declare @guilds varchar(max)
declare @maxRanks varchar(max)
declare @rulesId int
declare @knownList varchar(max)

set @guilds = 'white-path'
set @maxRanks = '9'
set @rulesId = 1
set @knownList = 'Bless-6,Courage-Range-3,Cure-Blindness-4,Cure-Disease-7,Dismiss-Undead-6,Heal-6'

exec [hqpad-character-allowed-invocations] @guilds, @maxRanks, @rulesId, @knownList
go









/*
declare	@rulesId int -- the rule set id.
declare	@skills varchar(max) -- comma list of skill slugs (those already bought by character).
declare	@ranks varchar(max) -- comma list of skill ranks (in same order as @skills).
declare	@guildLevel int -- the character guild rank.
declare	@primaryGuild varchar(250) -- the character primary guild slug (or null).
declare	@secondaryGuild varchar(250) -- the character secondary guild slug (or null).
declare	@tertiaryGuild varchar(250) -- the character tertiary guild slug (or null).
declare	@characterRank int -- the character rank.
declare	@pointsTable int -- the character points table id.

set @rulesId = 1
set @skills = 'life-points,recognise-magic,spell-slot-level-1,spell-slot-level-2,spell-slot-level-3,spell-slot-level-4,spell-slot-level-5,spell-slot-level-6,spell-slot-level-7,spell-slot-level-8,mnemonic-enhancer,extra-colour-3rd,extra-colour-4th,learn-level-18-spells,make-focus,recognise-power,buy-power,meditate,connection-with-1st-sphere,cast-rank-1st-sphere,read-write-runes'
set @ranks = '6,1,10,6,6,6,32,1,1,1,1,1,1,2,1,1,15,1,1,3,1'
set @guildLevel = '1'
set @primaryGuild = 'blue-school-of-magic'
set @secondaryGuild = ''
set @tertiaryGuild = ''
set @characterRank = 41
set @pointsTable = 2

exec hqpad_character_allowed_skills @rulesId, @skills, @ranks, @guildLevel, @primaryGuild, @secondaryGuild, @tertiaryGuild, @characterRank, @pointsTable
go
*/

/*
	-- convert skills list to table
	declare @skillTable Table
	(
		SkillID int,
		Ranks int
	)
	
	-- populate skills table
	insert into @skillTable
	select SkillID, CONVERT(int, y.Item)
	from Skill sk
	inner join udf_ItemParse(@skills, ',') x on x.Item = sk.Slug
	inner join udf_ItemParse(@ranks, ',') y on y.Pos = x.Pos
	where sk.RuleSetID = @rulesId

select * --COUNT(*) 
			from SkillRequirement sr
			left join @skillTable st on st.SkillID = sr.RequiredSkillID
			where sr.ParentSkillID = 66
			and sr.GuildID is null
			and sr.Combination = 'AND'
			and (
				(sr.MinRank is not null and sr.MinRank <= @characterRank) -- min rank passed.
				or
				(sr.SkillRequirementID is not null and st.SkillID is not null and coalesce(sr.QuantityRequired,1) <= st.Ranks) -- required skill present
			)
			*/